// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   LoginAction.java

package org.fiel.struts.actions;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.*;
import org.fiel.login.ValidateUser;
import org.fiel.struts.forms.LoginForm;

public class LoginAction extends Action
{

    public LoginAction()
    {
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String forwardName = "error";
        try
        {
            LoginForm loginForm = (LoginForm)form;
            org.fiel.login.FielPrincipal principal = null;
            ValidateUser validateUser = new ValidateUser();
            principal = validateUser.checkCredentials(loginForm.getUsername(), loginForm.getPassword());
            if(principal != null)
            {
                request.getSession().setAttribute("userPrincipal", principal);
                forwardName = "inicio";
            }
        }
        catch(Throwable e)
        {
            Log log = LogFactory.getLog(getClass().getName());
            log.error(e.getMessage());
            e.printStackTrace();
            return mapping.findForward(forwardName);
        }
        return mapping.findForward(forwardName);
    }
}
